using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Biblioteca.Objetos;
using Biblioteca.Utils;
using Pms.Utils;

namespace Pms
{
    public partial class Modulos : System.Web.UI.Page
    {
        Usuario usuAut;
        protected void Page_Load(object sender, EventArgs e)
        {
            //Se a sessao estiver expirada, retorna a tela de login
            if (Session.Count == 0)
            {
                Response.Redirect("~/Login.aspx");
            }
            else
            {
                usuAut = (Usuario)Session["usuario"];

                //Formatando nome para exibir na barra superior
                lblNome.Text = usuAut.Nome.Substring(0, usuAut.Nome.IndexOf(" "));

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), BiblioPMS.aplicacaoSEG))
                {
                    imgSEG.ImageUrl = "~/Imagens/SegPB.png";
                    imgSEG.Enabled = false;
                    imgSEG.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), BiblioPMS.aplicacaoSGA))
                {
                    imgAlmox.ImageUrl = "~/Imagens/AlmoxPB.png";
                    imgAlmox.Enabled = false;
                    imgAlmox.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), BiblioPMS.aplicacaoRH))
                {
                    imgFolhaComp.ImageUrl = "~/Imagens/RH1.png";
                    imgFolhaComp.Enabled = false;
                    imgFolhaComp.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), BiblioPMS.aplicacaoGUI))
                {
                    imgGuia.ImageUrl = "~/Imagens/GuiaPB.png";
                    imgGuia.Enabled = false;
                    imgGuia.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), BiblioPMS.aplicacaoSNG))
                {
                    imgNegocios.ImageUrl = "~/Imagens/NegPB.png";
                    imgNegocios.Enabled = false;
                    imgNegocios.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), BiblioPMS.aplicacaoSCN))
                {
                    imgContas.ImageUrl = "~/Imagens/ContaPB.png";
                    imgContas.Enabled = false;
                    imgContas.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), "8"))
                {
                    ImageButton3.ImageUrl = "~/Imagens/ContentPB.png";
                    ImageButton3.Enabled = false;
                    ImageButton3.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), "6"))
                {
                    ImageButton5.ImageUrl = "~/Imagens/PatriPB.png";
                    ImageButton5.Enabled = false;
                    ImageButton5.Visible = false;
                }

                if (!BiblioPMS.PermissaoSistema(usuAut.Login.ToUpper(), "7"))
                {
                    ImageButton6.ImageUrl = "~/Imagens/HelpPB.png";
                    ImageButton6.Enabled = false;
                    ImageButton6.Visible = false;
                }


            }
        }

        protected void imgFolhaComp_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Response.Redirect("~/Projetos/RH/Default.aspx");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        protected void imgAlmox_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Session.Add("pagAtual", 1);
                Response.Redirect("~/Projetos/SGA/Default.aspx");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        protected void imgSEG_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Response.Redirect("~/Projetos/SEG/Default.aspx");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        protected void imgGuia_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Response.Redirect("~/Projetos/GUI/Default.aspx");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        protected void imgContas_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Response.Redirect("~/Projetos/SCN/Default.aspx");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        protected void imgNegocios_Click1(object sender, ImageClickEventArgs e)
        {
            try
            {
                Session.Add("pagAtual", 1);
                Session.Add("pagAtualAg", 1);
                Response.Redirect("~/Projetos/SNG/Default.aspx");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
    }
}
